package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.WeakHashMap;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (
            Connection connection = DBUtil.getConnection();
            ){
            Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.gender,c.name,c.floor " +
                    "FROM teacher t,class c " +
                    "WHERE t.id = c.teacher_id " +
                    "AND t.name = '王克晶'";
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()){
                /*String name = rs.getString("t.name");
                String gender = rs.getString("t.gender");
                String className = rs.getString("c.name");
                String floor = rs.getString("c.floor");*/

                String name = rs.getString(1);
                String gender = rs.getString(2);
                String className =rs.getString(3);
                String floor = rs.getString(4);
                System.out.println(name + " " + gender + " " + className + " " + floor);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
